// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.7
package sys

import (
	"context"
	"hotgo/api/admin/storeorder"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
)

var (
	StoreOrder = cStoreOrder{}
)

type cStoreOrder struct{}

// List 查看订单列表
func (c *cStoreOrder) List(ctx context.Context, req *storeorder.ListReq) (res *storeorder.ListRes, err error) {
	list, totalCount, err := service.SysStoreOrder().List(ctx, &req.StoreOrderListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.StoreOrderListModel{}
	}

	res = new(storeorder.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出订单列表
func (c *cStoreOrder) Export(ctx context.Context, req *storeorder.ExportReq) (res *storeorder.ExportRes, err error) {
	err = service.SysStoreOrder().Export(ctx, &req.StoreOrderListInp)
	return
}

// Edit 更新订单
func (c *cStoreOrder) Edit(ctx context.Context, req *storeorder.EditReq) (res *storeorder.EditRes, err error) {
	err = service.SysStoreOrder().Edit(ctx, &req.StoreOrderEditInp)
	return
}

// View 获取指定订单信息
func (c *cStoreOrder) View(ctx context.Context, req *storeorder.ViewReq) (res *storeorder.ViewRes, err error) {
	data, err := service.SysStoreOrder().View(ctx, &req.StoreOrderViewInp)
	if err != nil {
		return
	}

	res = new(storeorder.ViewRes)
	res.StoreOrderViewModel = data
	return
}

// Delete 删除订单
func (c *cStoreOrder) Delete(ctx context.Context, req *storeorder.DeleteReq) (res *storeorder.DeleteRes, err error) {
	err = service.SysStoreOrder().Delete(ctx, &req.StoreOrderDeleteInp)
	return
}

// Status 更新订单状态
func (c *cStoreOrder) Status(ctx context.Context, req *storeorder.StatusReq) (res *storeorder.StatusRes, err error) {
	err = service.SysStoreOrder().Status(ctx, &req.StoreOrderStatusInp)
	return
}